<?php $this->_extends('_layouts/main_layout'); ?>
<?php $this->_block('resource'); ?>
	<script type="text/javascript" src="<?php echo JS_DIR; ?>imgpreview.full.0.22.jquery.js"></script>
<?php $this->_endblock(); ?>
<?php $this->_block('title'); ?>
	Pixel_Managerment Table
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>

<div id="content" class="box">
	<h1>Pixel_Managerment Table</h1>
	<div id="menu" class="box">
		<ul class="box">
			<li><a href="<?php echo url('pixelManager/insert');?>"><span>Add</span></a></li>
			<li><a href="<?php echo url('pixelManager/index');?>"><span>Pixel Manager</span></a></li>
		</ul>
	</div>
		<?php if (isset($infos)) 
				{
					foreach ($infos as $info)
					{
		?>
				<p class="msg info"><?php echo $info;?></p>
		<?php		}
				}
		?>
		
	<fieldset>
		<legend>Search</legend>
		<form action="<?echo url('pixelManager/tblindex'); ?>" method="get">
			<div class="row" id="search">
				<select name="field">
                    <option value="campaign" <?php echo ('campaign'==$field) ? 'selected="selected"' : ''; ?>>Campaign</option>
					<option value="pub" <?php echo ('pub'==$field) ? 'selected="selected"' : ''; ?>>Pub</option>
				</select> LIKE 
				<input type="text" name="condition" value="<?php echo isset($condition) ? $condition : ''; ?>"/>
				<input type="submit" value="Search" />
			</div>
		</form>
	</fieldset>
	<fieldset>
		<legend>Pixel_Managerment Table</legend>
		<table class="full-size" style="text-align: center;">
			<thead>
				<tr>
					<th style="width:5%">ID</th>
					<th style="width:10%">Campaign</th>
					<th style="width:10%">Pub</th>
					<th style="width:10%">Pla</th>
					<th style="width:10%">Rate</th>
					<th style="width:10%">Operate</th>
				</tr>
			</thead>
			<tbody>
				<?php 
					$posArr = array('basic_reg', 'full_reg');
					if ($tblPixels && count($tblPixels) > 0):
						foreach($tblPixels as $tblPixel): 
				?>
					<tr>
						<td><?php echo $tblPixel['id']; ?></td>
						<td><?php echo $tblPixel['campaign']; ?></td>
						<td><?php echo $tblPixel['pub']; ?></td>
						<td><?php echo $tblPixel['pla'];?></td>
						<td>
							<input type="text" class="rateval" value="<?php echo $tblPixel['peak'];?>" id="<?php echo $tblPixel['id']; ?>" style="width: 50px;" />%
							<input type="button" class="setRateBtn" value="Set" />
							<label style="color:#F00;"></label>
						</td>
						<td>
							<a href="<?php echo url('pixelManager/tblupdate', array('id'=>$tblPixel['id']));?>">Edit</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<a href="<?php echo url('pixelManager/tbldelete', array('id'=>$tblPixel['id']));?>">Delete</a>
						</td>
					</tr>
				<?php 
						endforeach; 
					endif;
				?>
			</tbody>
		</table>
	</fieldset>
</div>

<script type="text/javascript">
	$('.setRateBtn').click(function(){
		var rateval = $(this).parent().children('.rateval').val();
		var label = $(this).parent().children('label');
		if(isNaN(rateval) || rateval>100 ||rateval<0){
			label.html('Invalid peak!');
			return false;
		}
		var id = $(this).parent().children('.rateval').attr('id');
		$.ajax({
			type: 'post',
			url: '<?php echo url('pixelManager/setpeak');?>',
			data: {peak: rateval, id: id},
			success: function(rdata){
				label.html('Success!');
			}
		});	
	});
</script>

<?php $this->_endblock(); ?>